﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text; 

namespace VideoRentalShop.Model
{
    public class MovieDbInitializer : DropCreateDatabaseAlways<MovieDbContext>
    {
        protected override void Seed(MovieDbContext context)
        {
            context.Genres.AddOrUpdate(
                g => g.Title,
                new Genre { Title = "Przygodowy" },
                new Genre { Title = "Katastroficzny" },
                new Genre { Title = "Animowany" },
                new Genre { Title = "Horror" },
                new Genre { Title = "Thriller" },
                new Genre { Title = "Komedia" },
                new Genre { Title = "Romantyczny" },
                new Genre { Title = "Anime" },
                new Genre { Title = "Akcja" },
                new Genre { Title = "Science Fiction" },
                new Genre { Title = "Fantastyka" },
                new Genre { Title = "Klasyk" },
                new Genre { Title = "Dramat" },
                new Genre { Title = "Sensacja" },
                new Genre { Title = "Western" },
                new Genre { Title = "Serial" },
                new Genre { Title = "XXX" }
            );

            var client1 = new Client { CreateDate = DateTime.Now, Name = "Zdzisiek", LastName = "Karzełek", Blocked = false, Street = "Odległościowa 69/666", PostalCode = "12-123", Email = "mulek.jestem@takie.cos", City = "Koszalin", Pesel = "12345678912" };
            var client2 = new Client { CreateDate = DateTime.Now, Name = "Franek", LastName = "Lutnicki", Blocked = false, Street = "Brukselska 77B/3", PostalCode = "56-321", Email = "romek.jestem@takie.cos", City = "Koszalin", Pesel = "16395652812" };
            context.Clients.AddOrUpdate(
                c => new { c.Name, c.LastName },
                client1,
                client2,
                new Client { CreateDate = DateTime.Now, Name = "Mariusz", LastName = "Gupolek", Blocked = false, Street = "Najnowsza 13/5", PostalCode = "69-753", Email = "atomek.jestem@takie.cos", City = "Poznań", Pesel = "32165498732" }
            );
            var movie1 = new Movie { Title = "Transformers", Quantity = 3, Avaiable = 2, ReleaseDate = new DateTime(2011, 1, 1) };
            var movie2 = new Movie { Title = "Ten Niezręczny Moment", OriginalTitle = "That Awkward Moment", Quantity = 2, Avaiable = 1, ReleaseDate = new DateTime(2014, 5, 10) };
            var movie3 = new Movie { Title = "Jestem numerem cztery", OriginalTitle = "I am number four", Quantity = 1, Avaiable = 0, ReleaseDate = new DateTime(2010, 6, 15) };
            var movie4 = new Movie { Title = "Piraci z karaibów", OriginalTitle = "Pirates of the Caribean", Quantity = 3, Avaiable = 3, ReleaseDate = new DateTime(1992, 7, 13) };
            context.Movies.AddOrUpdate(
                x => x.Title,
                movie1,
                movie2,
                movie3,
                movie4
            );

            var order1 = new Order { Archived = false, Client = client1, MakeDate = DateTime.Now };
            order1.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(2), Movie = movie1 });
            order1.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(-1), Movie = movie2 });
            var order2 = new Order { Archived = true, Client = client2, MakeDate = DateTime.Now };
            order2.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(2), Movie = movie1 });
            order2.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(1), Movie = movie2 });
            var order3 = new Order { Archived = false, Client = client2, MakeDate = DateTime.Now };
            order3.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(2), Movie = movie3 });
            order3.OrderDetails.Add(new OrderDetails { MaxReturnDate = DateTime.Now.AddDays(-1), Movie = movie4, ReturnDate = DateTime.Now.AddDays(-2) });
            context.Orders.AddOrUpdate(
                o => new { o.MakeDate },
                order1,
                order2,
                order3
            );

            base.Seed(context);
        }
    }
}